<?php
declare (strict_types = 1);

namespace app\admin\controller;
use think\facade\Lang;
use think\facade\Cache;
use think\facade\Db;

class Index
{
    public function index()
    {

        cookie('think_lang','en-us');



        return '您好！这是一个[admin]示例应用';
    }

    public function test(){
        // 查询状态为1的用户数据 并且每页显示10条数据
        $list = Db::name('log')->order('id', 'desc')->paginate(10);
        // 获取分页显示
        $page = $list->render();
        // 渲染模板输出
        return view('', ['list' => $list, 'page' => $page,'name'=>'2']);
    }
    # 分页显示
    public function test3333(){
        // 查询状态为1的用户数据 并且每页显示10条数据
        $list = Db::name('log')->order('id', 'desc')->paginate(10);
        // 渲染模板输出
        return view('', ['list' => $list]);
    }

    # 场景验证
    public function test3(){
        $data = [
            'name'  => '',
            'age'   => 130,
            'email' => '111@qq.com',
        ];

        $validate = new \app\admin\validate\User;
        // 验证全部字段
        //$result = $validate->check($data);
        // 选取某个场景验证
        $result = $validate->scene('email')->check($data);

        if(!$result){
            echo $validate->getError();
        }

    }
    # 控制器单独验证
    public function test333()
    {
        $validate = \think\facade\Validate::rule([
            'name'  => 'require|max:25',
            'email' => 'email',
            'age' => 'require',
        ]);

        $data = [
            'name'  => '3333',
            'email' => 'thinkphp@qq.com',
            'age' => ''
        ];

        if (!$validate->check($data)) {
            print_r($validate->getError());
        }

    }

}
